//
//  ContentCell.m
//  ucas_on_hand
//
//  Created by DaveLam on 15/1/31.
//  Copyright (c) 2015年 ucas. All rights reserved.
//

#import "ContentCell.h"

@implementation ContentCell
@synthesize infobtn=_infobtn;
@synthesize contentLabel=_contentLabel;
@synthesize icon=_icon;
@synthesize separateBar=_separateBar;
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _infobtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
        [self.contentView addSubview:_infobtn];
        _infobtn.titleLabel.textColor=[UIColor whiteColor];
        UIFont* infoFont=[UIFont systemFontOfSize:10.0];
        [_infobtn.titleLabel setAttributedText:[[NSMutableAttributedString alloc] initWithString:@"1" attributes:@{NSFontAttributeName:infoFont}]];
        [_infobtn setBackgroundImage:[UIImage imageNamed:@"home_info_bg"] forState:UIControlStateNormal];
        
        [self setBackgroundColor:[UIColor colorWithRed:36/255.0 green:41/255.0 blue:48/255.0 alpha:0.95]];
        
        _contentLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
        _contentLabel.textColor=[UIColor whiteColor];
        UIFont* contentFont=[UIFont systemFontOfSize:24.0];
        [_contentLabel setAttributedText:[[NSMutableAttributedString alloc] initWithString:@"" attributes:@{NSFontAttributeName:contentFont}]];
        [self.contentView addSubview:_contentLabel];
        
        _icon=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        [self.contentView addSubview:_icon];
        
        _separateBar=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 2)];
        [_separateBar setBackgroundImage:[UIImage imageNamed:@"home_split"] forState:UIControlStateNormal];
        [self.contentView addSubview:_separateBar];
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGRect iconFrame=_icon.frame;
    NSInteger margin=self.revealSideInset.left + 10;
    iconFrame.origin.x=margin;
    iconFrame.origin.y=floorf((CGRectGetHeight(self.frame)-CGRectGetHeight(_icon.frame))/2.0);
    _icon.frame=iconFrame;
    
    margin=margin+30+10;
    CGRect contentFrame=_contentLabel.frame;
    contentFrame.origin.x=margin;
    contentFrame.origin.y=floorf((CGRectGetHeight(self.frame)-CGRectGetHeight(_contentLabel.frame))/2.0);
    _contentLabel.frame=contentFrame;
    
    _infobtn.frame=CGRectMake(CGRectGetWidth(self.contentView.frame)-CGRectGetWidth(_infobtn.frame)-10, floorf((CGRectGetHeight(self.frame)-CGRectGetHeight(_infobtn.frame))/2.0), CGRectGetWidth(_infobtn.frame), CGRectGetHeight(_infobtn.frame));
    
    CGRect newFrame=_separateBar.frame;
    newFrame.origin.x=self.revealSideInset.left;
    newFrame.origin.y=self.frame.size.height-newFrame.size.height;
    newFrame.size.width=self.frame.size.width-self.revealSideInset.left;
    _separateBar.frame=newFrame;
}

@end
